home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14739 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  64 lines

  1. Path: news.compuserve.com!newsmaster
  2. From: Philippe Verdy <100105.3120@compuserve.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: (no subject)
  5. Date: 1 Apr 1996 22:25:11 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <4jpl47$rjj@dub-news-svc-2.compuserve.com>
  8. NNTP-Posting-Host: dd07-044.compuserve.com
  9.  
  10. Ravi Annavajjhala <rannavaj> s'Θcrit :
  11. > Hi,
  12. >         I am using Borland C++ 4.52. I am trying to use templates
  13. >         and if I do not code the functions for my templates "inline",
  14. >         I am getting linker errors.
  15. >         Could someone please help .....
  16. > -- 
  17. > Ravi Annavajjhala
  18. > Intel Corporation
  19. > 1900 Prairie City Road
  20. > Folsom, CA 95630
  21. > rannavaj@mcd.intel.com
  22. > (916) 356 6491
  23. You need to implement your template methods, using the template
  24. specificator. But you're partly right: this code may be outlined
  25. provided you keep it within your include files, else you won't be
  26. able to reuse the template library in your apps.
  27.  
  28. Ex:
  29. template<class T>
  30. class X {
  31.   X();
  32.   virtual ~X();
  33.   void method();
  34.   static int member;
  35. }
  36.  
  37. template <class T>
  38. X<T>::X()
  39. {
  40.   ...
  41. }
  42.  
  43. template <class T>
  44. X<T>::~X()
  45. {
  46.   ...
  47. }
  48.  
  49. template <class T>
  50. void X<T>::method()
  51. {
  52.   ...
  53. }
  54.  
  55. template <class T>
  56. int X<T>::member = 0;
  57.  
  58. The main idea is here to prefix the template arguments
  59. on all your outline definitions, so that they can bind
  60. themselves to their appropriate template arguments and types.
  61.  
  62.